#!/usr/bin/env python3
"""
简化的Coordinator服务器测试
"""

import asyncio
import httpx

async def simple_test():
    """简单测试服务器功能"""
    print("🧪 简单测试Motor Coordinator Server...")
    
    async with httpx.AsyncClient(timeout=30) as client:
        # 测试根路径
        print("\n1. 测试根路径...")
        try:
            response = await client.get("http://localhost:8080/")
            print(f"✅ 根路径: {response.status_code}")
            print(f"   服务: {response.json()['service']}")
        except Exception as e:
            print(f"❌ 根路径失败: {e}")
            return False
        
        # 测试liveness
        print("\n2. 测试liveness...")
        try:
            response = await client.get("http://localhost:8080/liveness")
            print(f"✅ Liveness: {response.status_code}")
            data = response.json()
            print(f"   状态: {data['status']}")
            print(f"   实例数: {data['instance_count']}")
        except Exception as e:
            print(f"❌ Liveness失败: {e}")
            return False
        
        # 测试heartbeat
        print("\n3. 测试heartbeat...")
        try:
            response = await client.post("http://localhost:8080/heartbeat", 
                                       json={"status": "normal"})
            print(f"✅ Heartbeat: {response.status_code}")
            data = response.json()
            print(f"   状态: {data['status']}")
        except Exception as e:
            print(f"❌ Heartbeat失败: {e}")
            return False
        
        # 测试实例列表
        print("\n4. 测试实例列表...")
        try:
            response = await client.get("http://localhost:8080/instances")
            print(f"✅ 实例列表: {response.status_code}")
            data = response.json()
            print(f"   实例数: {data['count']}")
        except Exception as e:
            print(f"❌ 实例列表失败: {e}")
            return False
        
        # 测试状态
        print("\n5. 测试状态...")
        try:
            response = await client.get("http://localhost:8080/status")
            print(f"✅ 状态: {response.status_code}")
            data = response.json()
            print(f"   协调器状态: {data['coordinator_status']['instance_count']} 个实例")
        except Exception as e:
            print(f"❌ 状态失败: {e}")
            return False
    
    print("\n🎉 简单测试完成！")
    return True

if __name__ == "__main__":
    asyncio.run(simple_test())
